// 监听生成图片按钮点击事件
document.getElementById('generateBtn').addEventListener('click', () => {

// 监听DeepSeek总结按钮点击事件
document.getElementById('summarizeBtn').addEventListener('click', async () => {
  const text = document.getElementById('textInput').value;
  
  if (text.trim() === '') {
    alert('请输入要总结的文字内容');
    return;
  }
  
  try {
    const response = await fetch('https://ark.cn-beijing.volces.com/api/v3/chat/completions', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer 你的token'
      },
      body: JSON.stringify({
        model: 'deepseek-r1-250120',
        messages: [
          {"role": "system", "content": "使用一个金句总结全文最核心的内容"},
          {"role": "user", "content": text}
        ]
      })
    });
    
    const data = await response.json();
    const summary = data.choices[0].message.content;
    document.getElementById('textInput').value = summary;
  } catch (error) {
    console.error('总结失败:', error);
    alert('总结失败，请重试');
  }
});
  const text = document.getElementById('textInput').value;
  const style = document.getElementById('style').value;
  
  if (text.trim() === '') {
    alert('请输入文字内容');
    return;
  }
  
  // 生成图片预览
  generateImagePreview(text, style);
});

// 监听保存按钮点击事件
document.getElementById('saveBtn').addEventListener('click', () => {
  const canvas = document.createElement('canvas');
  const preview = document.getElementById('imagePreview');
  
  // 将预览内容绘制到canvas
  html2canvas(preview).then(canvas => {
    // 创建下载链接
    const link = document.createElement('a');
    link.download = '金句图片.png';
    link.href = canvas.toDataURL('image/png');
    link.click();
  });
});

// 生成图片预览
function generateImagePreview(text, style) {
  const preview = document.getElementById('imagePreview');
  const container = document.getElementById('previewContainer');
  
  // 清空预览区域
  preview.innerHTML = '';
  
  // 根据选择的风格应用不同样式
  preview.className = style;
  
  // 处理文本换行
  const paragraphs = text.split('\n').filter(p => p.trim() !== '');
  
  paragraphs.forEach(paragraph => {
    const p = document.createElement('p');
    p.textContent = paragraph;
    preview.appendChild(p);
  });
  
  // 显示预览区域
  container.classList.remove('hidden');
}